import useSWR from 'swr'
import { getUserInfo } from '@/api/index'

export function useUserInfo(userId: string) {
  const { data, error, isLoading, mutate } = useSWR(
    ['userInfo', userId],
    () => getUserInfo(userId),
    {
      revalidateOnFocus: false, // 失去焦点不自动重新请求
      dedupingInterval: 1000, // 1秒内重复请求只发一次
      shouldRetryOnError: false, // 不自动重试
    }
  )
  return { data, error, isLoading, mutate }
} 